home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -screenplay- / shareware / warpquake / warpquakesrc / chase.c < prev    next >
C/C++ Source or Header  |  2000-02-29  |  3KB  |  95 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // chase.c -- chase camera code
  21.  
  22. #include "quakedef.h"
  23.  
  24. cvar_t    chase_back = {"chase_back", "100"};
  25. cvar_t    chase_up = {"chase_up", "16"};
  26. cvar_t    chase_right = {"chase_right", "0"};
  27. cvar_t    chase_active = {"chase_active", "0"};
  28.  
  29. vec3_t    chase_pos;
  30. vec3_t    chase_angles;
  31.  
  32. vec3_t    chase_dest;
  33. vec3_t    chase_dest_angles;
  34.  
  35.  
  36. extern qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace);
  37.  
  38. void Chase_Init (void)
  39. {
  40.     Cvar_RegisterVariable (&chase_back);
  41.     Cvar_RegisterVariable (&chase_up);
  42.     Cvar_RegisterVariable (&chase_right);
  43.     Cvar_RegisterVariable (&chase_active);
  44. }
  45.  
  46. void Chase_Reset (void)
  47. {
  48.     // for respawning and teleporting
  49. //    start position 12 units behind head
  50. }
  51.  
  52. void TraceLine (vec3_t start, vec3_t end, vec3_t impact)
  53. {
  54.     trace_t    trace;
  55.  
  56.     memset (&trace, 0, sizeof(trace));
  57.     SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
  58.  
  59.     VectorCopy (trace.endpos, impact);
  60. }
  61.  
  62. void Chase_Update (void)
  63. {
  64.     int        i;
  65.     float    dist;
  66.     vec3_t    forward, up, right;
  67.     vec3_t    dest, stop;
  68.  
  69.  
  70.     // if can't see player, reset
  71.     AngleVectors (cl.viewangles, forward, right, up);
  72.  
  73.     // calc exact destination
  74.     for (i=0 ; i<3 ; i++)
  75.         chase_dest[i] = r_refdef.vieworg[i] 
  76.         - forward[i]*chase_back.value
  77.         - right[i]*chase_right.value;
  78.     chase_dest[2] = r_refdef.vieworg[2] + chase_up.value;
  79.  
  80.     // find the spot the player is looking at
  81.     VectorMA (r_refdef.vieworg, 4096, forward, dest);
  82.     TraceLine (r_refdef.vieworg, dest, stop);
  83.  
  84.     // calculate pitch to look at the same spot from camera
  85.     VectorSubtract (stop, r_refdef.vieworg, stop);
  86.     dist = DotProduct (stop, forward);
  87.     if (dist < 1)
  88.         dist = 1;
  89.     r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180;
  90.  
  91.     // move towards destination
  92.     VectorCopy (chase_dest, r_refdef.vieworg);
  93. }
  94.  
  95.